package co.wangdao.xingshaoye.utils;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.TextView;

import co.wangdao.xingshaoye.R;


/**
 * 自定义Dialog
 * @author WX
 */
@SuppressLint("ResourceAsColor")
public class Nickname_dialog extends Dialog{

    /**
     * 	Custom_Dialog dialog = new Custom_Dialog(this);
     dialog.addContentView(R.Layout.x, new LayoutParams(LayoutParams.WRAP_CONTENT, R.style.Custom_Dialog));
     dialog.show();
     */
    private Context mcontext;
    private View mContentView;


    public  Nickname_dialog(Context context,String type) {
        super(context, R.style.Custom_Dialog);
        mcontext = context;
        mContentView = LayoutInflater.from(context).inflate(R.layout.nickname_diglog, null);
        addContentView(mContentView
                , new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    }



    public Nickname_dialog setPositiveButton(int StringId, View.OnClickListener positiveListener){
        Button btOK = (Button) mContentView.findViewById(R.id.bt_ok);
        Button btCancel = (Button) mContentView.findViewById(R.id.bt_cancel);
        btOK.setVisibility(View.VISIBLE);
        btOK.setOnClickListener(positiveListener);
        if(View.VISIBLE==btOK.getVisibility() && View.VISIBLE==btCancel.getVisibility()){
            mContentView.findViewById(R.id.ll_lable).setVisibility(View.VISIBLE);
        }else{
            mContentView.findViewById(R.id.ll_lable).setVisibility(View.GONE);
        }
        return this;
    }

    public Nickname_dialog setNegativeButton(int StringId, View.OnClickListener negativeListener){
        Button btOK = (Button) mContentView.findViewById(R.id.bt_ok);
        Button btCancel = (Button) mContentView.findViewById(R.id.bt_cancel);
        btCancel.setVisibility(View.VISIBLE);
        btCancel.setOnClickListener(negativeListener);
        if(View.VISIBLE==btOK.getVisibility() && View.VISIBLE==btCancel.getVisibility()){
            mContentView.findViewById(R.id.ll_lable).setVisibility(View.VISIBLE);
        }else{
            mContentView.findViewById(R.id.ll_lable).setVisibility(View.GONE);
        }
        return this;
    }

    @SuppressLint("ResourceAsColor")
    public void setBtnConfirm(){
        Button btOK = (Button) mContentView.findViewById(R.id.bt_ok);
        btOK.setTextColor(  R.color.black);
        btOK.setClickable(false);
    }

    public void setMessage(String msg){
        TextView message = (TextView) mContentView.findViewById(R.id.message);
        message.setText(msg);
    }

    public void setMessage(int msgId){
        setMessage(mcontext.getString(msgId));
    }
}
